<template>
	<el-dialog
	  :title="isUpgrade ? '升级货品' : !dataForm.productId ? '新增货品' : '修改货品'"
	  :visible.sync="visible"
	  :before-close="close"
	  :close-on-click-modal="false"
	  width="30%">
	  <el-form ref="dataForm" :model="dataForm" :rules="dataRule" label-position="top" size="mini">
      <el-form-item prop="productCategoryId" label="货品分类">
        <el-select v-model="dataForm.productCategoryId" filterable v-if="categorys.length" placeholder="货品分类" style="width: 100%;">
          <el-option
            v-for="item in categorys"
            :key="item.productCategoryId"
            :label="item.productCategoryName"
            :value="item.productCategoryId">
          </el-option>
        </el-select>
      </el-form-item>
	  	<el-form-item prop="productName" label="品名" >
        <el-input v-model="dataForm.productName" placeholder="品名" @change="setProductName" style="background-color: aquamarine;"></el-input>
      </el-form-item>
      <el-form-item prop="productGmp" label="GMP编码">
        <el-input v-model="dataForm.productGmp" placeholder="GMP编码" @change="setProductGmp"></el-input>
      </el-form-item>
      <el-form-item v-if="yfb" prop="haveSupplierNumber" label="GMP编码中是否包含供应商代码">
        <el-switch
          v-model="dataForm.haveSupplierNumber"
          @change="changeHaveSupplierNumber()"
          active-color="#13ce66"
          inactive-color="#ff4949"
          active-text="包含"
          inactive-text="不包含"
          :active-value="0"
          :inactive-value="1">
        </el-switch>
      </el-form-item>
      <el-form-item v-if="dataForm.haveSupplierNumber == 0" prop="supplierNumber" label="供应商代码">
        <el-input v-model="dataForm.supplierNumber" placeholder="供应商代码"></el-input>
      </el-form-item>
      <el-form-item v-if="b" prop="haveVersionNumber" label="GMP编码中是否包含包材版本号">
        <el-switch
          v-model="dataForm.haveVersionNumber"
          @change="changeHaveVersionNumber()"
          active-color="#13ce66"
          inactive-color="#ff4949"
          active-text="包含"
          inactive-text="不包含"
          :active-value="0"
          :inactive-value="1">
        </el-switch>
      </el-form-item>
      <el-form-item v-if="dataForm.haveVersionNumber == 0" prop="supplierNumber" label="包材版本号">
        <el-input v-model="dataForm.versionNumber" placeholder="包材版本号"></el-input>
      </el-form-item>
      <el-form-item prop="productSpec" label="货品规格">
        <el-input v-model="productSpecShow" placeholder="货品规格"></el-input>
      </el-form-item>
      <el-form-item  prop="haveFormulaSpec" label="规格是否包含化学式">
        <el-switch
          v-model="dataForm.haveFormulaSpec"
          @change="resetFormulaSpec()"
          active-color="#13ce66"
          inactive-color="#ff4949"
          active-text="包含"
          inactive-text="不包含"
          :active-value="0"
          :inactive-value="1">
        </el-switch>
      </el-form-item>

      <el-form-item v-if="dataForm.productId" prop="storageConditions" label="贮存条件">
        <el-tag
          @click="checkMain(tag)"
          :key="tag.id"
          v-for="tag in storageConditions"
          closable
          :disable-transitions="false"
          @close="handleConditionsClose(tag)"
          :type="tag.mainCondition?'success':''"
          >
          {{tag.val}}
        </el-tag>
       <el-input
          class="input-new-condition"
          v-if="inputConditionVisible"
          v-model="inputConditionValue"
          ref="saveConditionInput"
          size="small"
          @keyup.enter.native="handleConditionInputConfirm"
          @blur="handleConditionInputConfirm">
        </el-input>
        <el-button v-else class="input-new-condition" size="small" @click="showConditionInput">+ 贮存条件</el-button>
      </el-form-item>

      <el-form-item v-if="cp" label="是否绑定中间产品(将显示某一批中间产品是否存在系统中)">
        <el-switch
          v-model="dataForm.bindingZp"
          active-color="#13ce66"
          inactive-color="#ff4949"
          active-text="是"
          inactive-text="否"
          :active-value="0"
          :inactive-value="1">
        </el-switch>
      </el-form-item>
      <el-form-item v-if="cp || zp" label="生产车间">
        <el-select v-model="dataForm.workshopId" filterable v-if="workshops.length" placeholder="生产车间" style="width: 100%;">
          <el-option
            v-for="item in workshops"
            :key="item.workshopId"
            :label="item.workshopName"
            :value="item.workshopId">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item v-if="dataForm.productId" prop="productPackSpecs" label="包装规格">
        <el-tag
          :key="tag.productPackSpecId"
          v-for="tag in productPackSpecs"
          closable
          :disable-transitions="false"
          @close="handleClose(tag)">
          {{tag.productPackSpec}}
        </el-tag>
        <el-input
          class="input-new-tag"
          v-if="inputVisible"
          v-model="inputValue"
          ref="saveTagInput"
          size="small"
          @keyup.enter.native="handleInputConfirm"
          @blur="handleInputConfirm">
        </el-input>
        <el-button v-else class="button-new-tag" size="small" @click="showInput">+ 包装规格</el-button>
      </el-form-item>
      <el-form-item v-if="cp" prop="productValidity" label="货品有效期">
        <el-input @change="changeValidity" v-model="dataForm.productValidity" placeholder="货品有效期">
          <template slot="append">月</template>
        </el-input>
      </el-form-item>

      <template v-if="!ys">
        <el-form-item v-for="(ser, serIndex) in dataForm.serials" :key="serIndex" :label="'报告流水号('+ser.serialYear+')'">
          <el-input v-model="ser.serialNumber" @change="setSerialNumber(serIndex)" :placeholder="ser.serialYear+'年 的报告流水号'" />
        </el-form-item>
        <template>
          <el-tooltip effect="dark" content="增加其他年份的报告流水号" placement="top">
            <el-button type="primary" size="mini" icon="el-icon-plus" circle @click="addSerial"></el-button>
          </el-tooltip>
        </template>
      </template>

      <template v-if="ys">
        <el-form-item v-for="(w,wi) in waterWorkshops" :key="wi" :label="w.workshopName + '(' + w.workshopCode + ')报告流水号' + '(' + w.serialYear + ')'">
          <el-input v-model="w.serialNumber" @change="setWorkshopSerialNumber(wi)" placeholder="w.workshopName" />
        </el-form-item>
        <template>
          <el-tooltip effect="dark" content="增加其他年份的报告流水号" placement="top">
            <el-button type="primary" size="mini" icon="el-icon-plus" circle @click="addSerial"></el-button>
          </el-tooltip>
        </template>
      </template>
	  </el-form>
	  <span slot="footer" class="dialog-footer">
	    <el-button @click="close">取 消</el-button>
	    <el-button type="primary" class="pan-btn primary-btn" @click="dataFormSubmit('dataForm')">确 定</el-button>
  	</span>
	</el-dialog>
</template>

<script>
	import {
    getProductCategorys,
    saveOrUpdateProduct,
    getProductPackSpecsByProductId,
    getStorageConditionsByProductId,
    getProductSerialsByProductIdOrPrefix,
    saveProductPackSpec,
    deleteProductPackSpec,
    saveStorageConditions,
    deleteStorageConditions,
    getWaterWorkshopByProductId
  } from '@/api/product'
  import { getWorkshopList } from "@/api/workshop"
	import {isNumber,isPositiveIntegerNumber,is0OrPositiveIntegerNumber} from '@/common/js/validate'
  import {isBlank,unique} from '@/common/js/utils'
  import {CODE_OK} from '@/common/js/config'
	export default {
		data() {
			return {
				visible: false,
				categorys: "",
        workshops: [],
        waterWorkshops: [],
        isUpgrade: false,
        storageConditions:[],
				dataForm: {
					productGmp: "",
					productSpec: "",
					pleaseCheckCycle: "",
          samplingCycle: "",
          receivedSampleCycle: "",
          separateSampleCycle: "",
          getCycle: "",
					productCategoryId: "",
          workshopId: "",
          productValidity: "",
          haveProcess: 1,
          haveFormulaSpec: 1,
          haveSupplierNumber: 1,
          supplierNumber: null,
          versionNumber: null,
          haveVersionNumber: 1,
          bindingZp: 1,
          serialNumber: 0,
          serials: []
				},
        productSpecShow: "",
        productPackSpecs: [],
        inputVisible: false,
        inputValue: '',
        inputConditionValue:'',
        inputConditionVisible:false,
        span1: "<span style='font-size:9px'>",
        span2: "</span>",
				dataRule: {
					productName: [
          	{ required: true, message: '品名不能为空', trigger: 'blur' }
        	],
        	productGmp: [
          	{ required: true, message: 'GMP编码不能为空', trigger: 'blur' }
        	],
        	productCategoryId: [
          	{ required: true, message: '请选择货品分类', trigger: 'blur' }
        	]
				}
			}
		},
		props: ["childDataForm"],
    computed: {
      yfb() {
        return this.dataForm.productCategoryId == 1 || this.dataForm.productCategoryId == 2 || this.dataForm.productCategoryId == 3 || this.dataForm.productCategoryId == 9
      },
      b() {
        return this.dataForm.productCategoryId == 3
      },
      zp() {
        return this.dataForm.productCategoryId == 4
      },
      cp() {
        return this.dataForm.productCategoryId == 5
      },
      ys() {
        return this.dataForm.productCategoryId == 7
      }
    },
		created() {
			if (!isBlank(this.childDataForm)) {
				this.dataForm = this.childDataForm
        this.isUpgrade = this.dataForm.isUpgrade ? true : false
        let span1 = this.span1
        let span2 = this.span2
        if (!isBlank(this.dataForm.productSpec)) {
          this.productSpecShow = this.dataForm.productSpec.replace(new RegExp(span1, "gm"),"").replace(new RegExp(span2, "gm"),"")
        }
			}
      this.init()
			this.visible = true
			this.getProductInfo()
      this.$watch('productSpecShow', _ => { this.dataForm.productSpec = JSON.parse(JSON.stringify(this.productSpecShow)) })
		},
		methods: {
      checkMain(row){
        if(this.storageConditions.length == 1){
          this.storageConditions[0].mainCondition = true;
        }else{
          for(let condition of this.storageConditions){
            condition.mainCondition = false;
          }
          row.mainCondition = true;
        }
        // if(this.storageConditions.length == 1){}
        //   row.mainCondition = true;
        //   return;
        // }
        // for(let tag of this.storageConditions){
        //   console.log(tag)
        //   //tag.mainCondition = false
        // }
          //row.mainCondition = !row.mainCondition;
        },
      addSerial() {
        this.$prompt('请输入年份', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          inputPattern: /^(20\d\d)$/,
          inputErrorMessage: '请输入 20XX'
        }).then(({ value }) => {
          if (this.ys) {
            this.addWaterWorkshop(value)
          }else{
            this.serialsPush(value, 0)
          }
        }).catch(()=>{})
      },
      init() {
        // 属于新增，设置默认值
        if (isBlank(this.dataForm.productId) && !this.ys) {
          this.serialsPush(this.moment(new Date()).format('YYYY'), 0)
        }
      },
      serialsPush(y, n) {
        if (isBlank(this.dataForm.serials)) {
          this.dataForm.serials = []
        }else{
          if (this.dataForm.serials.findIndex(v => v.serialYear == y) > -1) {
            this.$message.error('当前年份已经有值')
            return
          }
        }
        this.dataForm.serials.push({
          serialYear: y,
          serialNumber: n
        })
      },
      resetFormulaSpec() {
        this.dataForm.productSpec = JSON.parse(JSON.stringify(this.productSpecShow))
      },
      selectFormula() {
        let content = window.getSelection().toString()
        if (content != ''){
          let len = content.length
          let position1 = this.dataForm.productSpec.indexOf(content)
          let position2 = position1 + len
          let tempstr1 = this.dataForm.productSpec.substring(0,position1)
          let tempstr2 = this.dataForm.productSpec.substring(position2)
          let contentArr = content.split("")
          let sb = ""
          for (let i=0,j=contentArr.length; i<j; i++) {
            let str = contentArr[i]
            if (isNumber(str)){
              str = this.span1 + str + this.span2
            }
            sb = sb + str
          }
          this.dataForm.productSpec = tempstr1 + sb + tempstr2
        }
      },
      handleConditionsClose(tag){
        if (tag.id){
          deleteStorageConditions(tag.id).then(res=>{
            if (res.code === CODE_OK) {
              const params = {
                productId: this.dataForm.productId
              }
              getStorageConditionsByProductId(params).then(res => {
                if (res.code === CODE_OK) {
                	this.storageConditions = res.storageConditions
                }else{
                  this.$message.error(res.msg)
                }
              })
            }else{
              this.$message.error(res.msg)
            }
          });
        }
      },
      handleClose(tag) {
        if (tag.productPackSpecId){
          deleteProductPackSpec(tag.productPackSpecId).then(res => {
            if (res.code === CODE_OK) {
              const params = {
                productId: this.dataForm.productId
              }
              getProductPackSpecsByProductId(params).then(res => {
                if (res.code === CODE_OK) {
                	this.productPackSpecs = res.productPackSpecs
                }else{
                  this.$message.error(res.msg)
                }
              })
            }else{
              this.$message.error(res.msg)
            }
          })
        }
      },
      showInput() {
        this.inputVisible = true
        this.$nextTick(_ => {
          this.$refs.saveTagInput.$refs.input.focus()
        })
      },
      showConditionInput(){
        this.inputConditionVisible = true
        this.$nextTick(_ => {
          this.$refs.saveConditionInput.$refs.input.focus()
        })
      },
      handleConditionInputConfirm(){
        let inputValue = this.inputConditionValue
        if (inputValue && this.dataForm.productId) {
          const data = {
            val: inputValue,
            productId: this.dataForm.productId
          }
          saveStorageConditions(data).then(res => {
            if (res.code === CODE_OK) {
              this.$message.success('保存成功')
              const params = {
                productId: this.dataForm.productId
              }
              getStorageConditionsByProductId(params).then(res => {
                if (res.code === CODE_OK) {
                	this.storageConditions = res.storageConditions
                }else{
                  this.$message.error(res.msg)
                }
              })
            }else{
              this.$message.error(res.msg)
            }
          })
        }else{
          this.$message.error("请先保存货品信息且输入的贮存条件不能为空")
        }
        this.inputConditionVisible = false
        this.inputConditionValue = ''
      },
      handleInputConfirm() {
        let inputValue = this.inputValue
        if (inputValue && this.dataForm.productId) {
          // if (inputValue.length > 7) {
          //   this.$message.error('包装规格长度过长，请检查包装规格，并非报告书上的包装规格(示例：10支/盒)')
          //   return
          // }
          // let t = inputValue.substring(inputValue.length-2)
          // if (t != '/盒' && t != '/瓶' && t != '/袋') {
          //   this.$message.error('包装规格必须以‘/盒’或‘/瓶’或‘/袋’为结尾)')
          //   return
          // }
          const data = {
            productPackSpec: inputValue,
            productId: this.dataForm.productId
          }
          saveProductPackSpec(data).then(res => {
            if (res.code === CODE_OK) {
              this.$message.success('保存成功')
              const params = {
                productId: this.dataForm.productId
              }
              getProductPackSpecsByProductId(params).then(res => {
                if (res.code === CODE_OK) {
                	this.productPackSpecs = res.productPackSpecs
                }else{
                  this.$message.error(res.msg)
                }
              })
            }else{
              this.$message.error(res.msg)
            }
          })
        }else{
          this.$message.error("请先保存货品信息且输入的包装规格不能为空")
        }
        this.inputVisible = false
        this.inputValue = ''
      },
			close() {
				this.$emit('close')
				this.$emit('refreshData')
				this.visible = false
			},
			getProductInfo() {
				getProductCategorys().then(res => {
					if (res.code === CODE_OK) {
						this.categorys = res.categorys
					}
				})
        const params = {
          productId: this.dataForm.productId
        }
        if (this.dataForm.productId != null) {
          getProductPackSpecsByProductId(params).then(res => {
            if (res.code === CODE_OK) {
            	this.productPackSpecs = res.productPackSpecs
            }else{
              this.$message.error(res.msg)
            }
          })
          getStorageConditionsByProductId(params).then(res=>{
            if (res.code === CODE_OK) {
            	this.storageConditions = res.storageConditions
            }else{
              this.$message.error(res.msg)
            }
          })
          const params2 = {
            productGmpPrefix: this.getProductGmpPrefix()
          }
          getProductSerialsByProductIdOrPrefix(params2).then(res => {
            if (res.code === CODE_OK) {
              this.dataForm.serials = res.list
            }else{
              this.$message.error(res.msg)
            }
          })
        }
        const params1 = {
        	page: 1,
          limit: 99
        }
        getWorkshopList(params1).then(res => {
        	if (res.code === CODE_OK) {
        		this.workshops = res.page.list.map(v => {
              this.$set(v,'serialNumber', 0)
              this.$set(v,'serialYear',this.moment(new Date()).format('YYYY'))
              return v
            })
            this.waterWorkshops = JSON.parse(JSON.stringify(this.workshops))
            if (this.dataForm.productId != null) {
              getWaterWorkshopByProductId(params).then(res => {
                if (res.code === CODE_OK) {
                  let wws = res.list
                  let allSerialYear = unique(wws.map(v => {return v.serialYear}))
                  if (!(allSerialYear.length == 1 && allSerialYear[0] == this.moment(new Date()).format('YYYY'))) {
                    this.waterWorkshops = []
                    for (let sy of allSerialYear) {
                      this.addWaterWorkshop(sy)
                    }
                  }
                  for (let ww of wws) {
                    for (let i=0,j=this.waterWorkshops.length; i<j; i++) {
                      if (ww.workshopId == this.waterWorkshops[i].workshopId && ww.serialYear == this.waterWorkshops[i].serialYear) {
                        this.waterWorkshops[i].serialNumber = ww.serialNumber
                        break
                      }
                    }
                  }
                }
              })
            }
        	}else{
        		this.$message.error(res.msg)
        	}
        })
			},
      addWaterWorkshop(serialYear) {
        if (this.waterWorkshops.findIndex(v => v.serialYear == serialYear) > -1) {
          this.$message.error("已经有"+serialYear+"年份")
          return
        }
        let ws = JSON.parse(JSON.stringify(this.workshops))
        let arr = ws.map(v => {
          this.$set(v,'serialNumber', 0)
          this.$set(v,'serialYear',serialYear)
          return v
        })
        this.waterWorkshops.push(...arr)
      },
			dataFormSubmit(form) {
				this.$refs[form].validate(valid => {
					if (valid) {
            if (this.formVerify()) {
              this.dataForm.storageConditions = this.storageConditions;
              saveOrUpdateProduct(this.dataForm).then(res => {
              	if (res.code === CODE_OK) {
              		this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1500,
                    onClose: this.close()
                })
              	}else{
              		this.$message.error(res.msg)
              	}
              })
            }
					}else{
						this.$message.error("请按要求填写")
					}
				})
			},
      formVerify() {
        //中间品
        if (this.zp || this.cp) {
          if (isBlank(this.dataForm.workshopId)) {
            this.$message.error('请选择生产车间')
            return false
          }
          //成品
          if (this.cp) {
            if (isBlank(this.dataForm.productValidity)) {
              this.$message.error('请填写成品有效期')
              return false
            }
            this.dataForm.haveProcess = 0
          }
        }
        //不是水
        if (!this.ys) {
          let productGmpPrefix = this.getProductGmpPrefix()
          for (let i=0,j=this.dataForm.serials.length; i<j; i++) {
            if (!is0OrPositiveIntegerNumber(this.dataForm.serials[i].serialNumber)) {
              this.$message.error('报告书流水号必须为正整数')
              return false
            }else{
              this.$set(this.dataForm.serials[i],'productGmpPrefix',productGmpPrefix)
            }
          }
        }else{
          this.dataForm.serials = null
          for (let i=0,j=this.waterWorkshops.length; i<j; i++) {
            if (!is0OrPositiveIntegerNumber(this.waterWorkshops[i].serialNumber)) {
              this.$message.error('报告书流水号必须为正整数')
              return false
            }
          }
          this.$set(this.dataForm,'wws',this.waterWorkshops)
        }
        return true
      },
      getProductGmpPrefix() {
        let pgp = this.dataForm.productGmp
        if (this.dataForm.haveSupplierNumber == 0) {
          pgp = pgp.substring(0,pgp.length-2)
        }else if (this.dataForm.haveVersionNumber == 0) {
          pgp = pgp.substring(0,pgp.length-3)
        }
        return pgp
      },
      setSerialNumber(index) {
        if (!is0OrPositiveIntegerNumber(this.dataForm.serials[index].serialNumber)) {
          this.$message.error('请输入正整数')
          this.dataForm.serials[index].serialNumber = 0
        }
      },
      setWorkshopSerialNumber(wi) {
        let sn = this.waterWorkshops[wi].serialNumber
        if (!is0OrPositiveIntegerNumber(sn)) {
          this.$message.error('请输入正整数')
          this.waterWorkshops[wi].serialNumber = 0
          return
        }
        let wcode = this.waterWorkshops[wi].workshopCode
        let sy = this.waterWorkshops[wi].serialYear
        this.waterWorkshops.forEach(w => {
          if (w.workshopCode == wcode && w.serialYear == sy) {
            w.serialNumber = sn
          }
        })
      },
      setProductGmp() {
        let gmp = JSON.parse(JSON.stringify(this.dataForm.productGmp))
        //过滤-
        gmp = gmp.replace(/一/g,'-')
        gmp = gmp.replace(/－/g,'-')
        gmp = gmp.replace(/—/g,'-')
        //转大写
        gmp = gmp.toUpperCase()
        //中文括号换英文括号
        gmp = gmp.replace(/（/g,'(')
        gmp = gmp.replace(/）/g,')')
        //如果不是CK开头，去空格
        if (gmp.substring(0,2) != 'CK' && gmp.indexOf(' ') > -1) {
          gmp = gmp.replace(/ /g,'')
          this.$message.info("系统已自动去掉空格")
        }
        //判断是否含有供应商代码
        this.dataForm.haveSupplierNumber = 1
        let last2 = gmp.substring(gmp.length - 2)
        if (last2 == '-A'
          || last2 == '-B'
          || last2 == '-C'
          || last2 == '-D'
          || last2 == '-E'
          || last2 == '-F'
          || last2 == '-G'
          || last2 == '-H'
          || last2 == '-I') {
            let last1 = gmp.substring(gmp.length - 1)
            this.dataForm.haveSupplierNumber = 0
            this.dataForm.supplierNumber = last1
            this.$message.info('检测GMP编码中含有供应商代码,已自动填写')
        }
        //判断是否含有包材版本号
        this.dataForm.haveVersionNumber = 1
        this.dataForm.versionNumber = null
        let last3 = gmp.substring(gmp.length - 3)
        if (last3 == '-00'
          || last3 == '-01'
          || last3 == '-02'
          || last3 == '-03'
          || last3 == '-04'
          || last3 == '-05'
          || last3 == '-06'
          || last3 == '-07'
          || last3 == '-08'
          || last3 == '-09'
          || last3 == '-10'
          || last3 == '-11'
          || last3 == '-12'
          || last3 == '-13'
          || last3 == '-14'
          || last3 == '-15'
          || last3 == '-16'
          || last3 == '-17'
          || last3 == '-18'
          || last3 == '-19'
          || last3 == '-20'
          || last3 == '-21'
          || last3 == '-22'
          || last3 == '-23'
          || last3 == '-24'
          || last3 == '-25'
          || last3 == '-26'
          || last3 == '-27'
          || last3 == '-28'
          || last3 == '-29'
          || last3 == '-30') {
            this.dataForm.haveVersionNumber = 0
            this.dataForm.versionNumber = last2
            this.$message.info('检测到GMP编码中含有包材版本号,已自动填写')
        }
        this.dataForm.productGmp = gmp
      },
      setProductName() {
        //中文括号换英文括号
        this.dataForm.productName = this.dataForm.productName.replace(/（/g,'(')
        this.dataForm.productName = this.dataForm.productName.replace(/）/g,')')
      },
	  setPleaseCheckCycle() {
        //中文括号换英文括号
        this.dataForm.pleaseCheckCycle = this.dataForm.pleaseCheckCycle.replace(/（/g, '(')
        this.dataForm.pleaseCheckCycle = this.dataForm.pleaseCheckCycle.replace(/）/g, ')')
      },
      setSamplingCycle() {
        //中文括号换英文括号
        this.dataForm.samplingCycle = this.dataForm.samplingCycle.replace(/（/g, '(')
        this.dataForm.samplingCycle = this.dataForm.samplingCycle.replace(/）/g, ')')
      },setReceivedSampleCycle() {
        //中文括号换英文括号
        this.dataForm.receivedSampleCycle = this.dataForm.receivedSampleCycle.replace(/（/g, '(')
        this.dataForm.receivedSampleCycle = this.dataForm.receivedSampleCycle.replace(/）/g, ')')
      },setSeparateSampleCycle() {
        //中文括号换英文括号
        this.dataForm.separateSampleCycle = this.dataForm.separateSampleCycle.replace(/（/g, '(')
        this.dataForm.separateSampleCycle = this.dataForm.separateSampleCycle.replace(/）/g, ')')
      },setGetCycle() {
        //中文括号换英文括号
        this.dataForm.getCycle = this.dataForm.getCycle.replace(/（/g, '(')
        this.dataForm.getCycle = this.dataForm.getCycle.replace(/）/g, ')')
      },
      changeHaveSupplierNumber() {
        if (this.dataForm.haveSupplierNumber == 0) {
          //设置供应商代码
          if (this.dataForm.haveVersionNumber == 0) {
            this.dataForm.haveVersionNumber = 1
            this.dataForm.versionNumber = null
          }
        }else{
          this.dataForm.supplierNumber = null
        }
      },
      changeHaveVersionNumber() {
        if (this.dataForm.haveVersionNumber == 0) {
          //设置版本号
          if (this.dataForm.haveSupplierNumber == 0) {
            this.dataForm.haveSupplierNumber = 1
            this.dataForm.supplierNumber = null
          }
        }else{
          this.dataForm.versionNumber = null
        }
      },
      changeValidity() {
        if (!isPositiveIntegerNumber(this.dataForm.productValidity)) {
          this.dataForm.productValidity = null
          this.$message.error('有效期应为正整数')
          return
        }
      }
    }
	}
</script>

<style scoped>
  .el-tag + .el-tag {
    margin-left: 10px;
  }
  .button-new-tag {
    margin-left: 10px;
    height: 32px;
    line-height: 30px;
    padding-top: 0;
    padding-bottom: 0;
  }
  .input-new-tag {
    width: 90px;
    margin-left: 10px;
    vertical-align: bottom;
  }

  .input-new-condition{
    width: 90px;
    margin-left: 10px;
    vertical-align: bottom;
  }
</style>
